package com.example.imtoken.modules.login

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPUtils
import com.example.imtoken.R
import com.example.imtoken.core.App
import com.example.imtoken.core.base.BaseViewModel
import com.example.imtoken.core.utils.sp.SpHelps
import com.example.imtoken.entitys.app.BannerItem
import java.util.*

class LoginViewModel : BaseViewModel() {

    private val bannerLiveData = MutableLiveData<MutableList<BannerItem>>()

    fun getBannerLiveData(): MutableLiveData<MutableList<BannerItem>> {
        return bannerLiveData
    }

    fun getBannerData() {
        val data = ArrayList<BannerItem>()
        data.add(BannerItem(R.mipmap.src_lib_eui_icon_landing1, R.string.bannerTitle1))
        data.add(BannerItem(R.mipmap.src_lib_eui_icon_landing2, R.string.bannerTitle2))
        data.add(BannerItem(R.mipmap.src_lib_eui_icon_landing3, R.string.bannerTitle3))
        bannerLiveData.value = data
    }

    /**
     * 获取剪切板内容,截取推广码
     * @param uri String
     */
    fun getExtensionCode(uri: String) {
        val indexOf = uri.indexOf("xxxxx=")
        if (indexOf > -1) {
            val startIndex = indexOf + 6
            val endIndex = indexOf + 12
            val code = uri.substring(startIndex, endIndex)
            SPUtils.getInstance(SpHelps.APP).put(SpHelps.APP_CODE, code)
            App.appCode = code
        } else {
            LogUtils.e("未知内容")
        }
    }

}